home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / addnew / addnew.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-05-07  |  9.1 KB  |  265 lines

  1. VERSION 2.00
  2. Begin Form AddNewRelationship 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "AddNew - Relationships"
  5.    ClientHeight    =   4305
  6.    ClientLeft      =   3180
  7.    ClientTop       =   3300
  8.    ClientWidth     =   7320
  9.    Height          =   4995
  10.    Left            =   3120
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4305
  13.    ScaleWidth      =   7320
  14.    Top             =   2670
  15.    Width           =   7440
  16.    Begin CommandButton Command2 
  17.       Caption         =   "AddNew to Secondary Table"
  18.       FontBold        =   0   'False
  19.       FontItalic      =   0   'False
  20.       FontName        =   "MS Sans Serif"
  21.       FontSize        =   8.25
  22.       FontStrikethru  =   0   'False
  23.       FontUnderline   =   0   'False
  24.       Height          =   495
  25.       Left            =   3360
  26.       TabIndex        =   1
  27.       Top             =   3240
  28.       Width           =   2895
  29.    End
  30.    Begin TextBox Text5 
  31.       DataField       =   "SecondInfo"
  32.       DataSource      =   "Data2"
  33.       Height          =   405
  34.       Left            =   3240
  35.       TabIndex        =   8
  36.       Text            =   "Text5"
  37.       Top             =   1920
  38.       Width           =   1335
  39.    End
  40.    Begin TextBox Text4 
  41.       DataField       =   "MasterID"
  42.       DataSource      =   "Data2"
  43.       Height          =   375
  44.       Left            =   3240
  45.       TabIndex        =   7
  46.       Text            =   "Text4"
  47.       Top             =   960
  48.       Width           =   1335
  49.    End
  50.    Begin CommandButton Command1 
  51.       Caption         =   "AddNew to Master Table"
  52.       FontBold        =   0   'False
  53.       FontItalic      =   0   'False
  54.       FontName        =   "MS Sans Serif"
  55.       FontSize        =   8.25
  56.       FontStrikethru  =   0   'False
  57.       FontUnderline   =   0   'False
  58.       Height          =   495
  59.       Left            =   240
  60.       TabIndex        =   6
  61.       Top             =   3240
  62.       Width           =   2535
  63.    End
  64.    Begin TextBox Text3 
  65.       DataField       =   "SecondaryID"
  66.       DataSource      =   "Data2"
  67.       Height          =   375
  68.       Left            =   3240
  69.       TabIndex        =   5
  70.       TabStop         =   0   'False
  71.       Text            =   "Text3"
  72.       Top             =   10
  73.       Width           =   1335
  74.    End
  75.    Begin TextBox Text2 
  76.       DataField       =   "MasterInfo"
  77.       DataSource      =   "Data1"
  78.       Height          =   375
  79.       Left            =   120
  80.       TabIndex        =   0
  81.       Text            =   "Text2"
  82.       Top             =   1920
  83.       Width           =   2055
  84.    End
  85.    Begin TextBox Text1 
  86.       DataField       =   "MasterID"
  87.       DataSource      =   "Data1"
  88.       Height          =   375
  89.       Left            =   120
  90.       TabIndex        =   2
  91.       TabStop         =   0   'False
  92.       Text            =   "Text1"
  93.       Top             =   960
  94.       Width           =   1215
  95.    End
  96.    Begin Data Data2 
  97.       Caption         =   "Secondary Table"
  98.       Connect         =   ""
  99.       DatabaseName    =   "C:\ADDNEW\addnew.mdb"
  100.       Exclusive       =   0   'False
  101.       Height          =   270
  102.       Left            =   3360
  103.       Options         =   0
  104.       ReadOnly        =   0   'False
  105.       RecordSource    =   "Secondary"
  106.       Top             =   3840
  107.       Width           =   2895
  108.    End
  109.    Begin Data Data1 
  110.       Caption         =   "Master Table"
  111.       Connect         =   ""
  112.       DatabaseName    =   "C:\ADDNEW\addnew.mdb"
  113.       Exclusive       =   0   'False
  114.       Height          =   270
  115.       Left            =   240
  116.       Options         =   0
  117.       ReadOnly        =   0   'False
  118.       RecordSource    =   "Master"
  119.       Top             =   3840
  120.       Width           =   2535
  121.    End
  122.    Begin Label Label5 
  123.       BackColor       =   &H00C0C0C0&
  124.       Caption         =   "Just Information.  Field Format = TEXT"
  125.       Height          =   375
  126.       Left            =   3240
  127.       TabIndex        =   11
  128.       Top             =   2400
  129.       Width           =   1935
  130.    End
  131.    Begin Label Label4 
  132.       BackColor       =   &H00C0C0C0&
  133.       Caption         =   "Master Table/Secondary Table Relationship field.  Field Format = Number, Long Integer"
  134.       Height          =   495
  135.       Left            =   3240
  136.       TabIndex        =   10
  137.       Top             =   1320
  138.       Width           =   3975
  139.    End
  140.    Begin Label Label3 
  141.       BackColor       =   &H00C0C0C0&
  142.       Caption         =   "Secondary Table ID Field Field Format = Counter"
  143.       Height          =   375
  144.       Left            =   3240
  145.       TabIndex        =   9
  146.       Top             =   425
  147.       Width           =   2175
  148.    End
  149.    Begin Line Line1 
  150.       X1              =   3000
  151.       X2              =   3000
  152.       Y1              =   120
  153.       Y2              =   3720
  154.    End
  155.    Begin Label Label2 
  156.       BackColor       =   &H00C0C0C0&
  157.       Caption         =   "Just Information.  Field Format = TEXT"
  158.       Height          =   375
  159.       Left            =   120
  160.       TabIndex        =   3
  161.       Top             =   2400
  162.       Width           =   1935
  163.    End
  164.    Begin Label Label1 
  165.       BackColor       =   &H00C0C0C0&
  166.       Caption         =   "Master Table ID Field,  Field Format = Counter"
  167.       Height          =   375
  168.       Left            =   120
  169.       TabIndex        =   4
  170.       Top             =   1320
  171.       Width           =   2055
  172.    End
  173.    Begin Menu mnuExit 
  174.       Caption         =   "E&xit"
  175.    End
  176.    Begin Menu mnuAbout 
  177.       Caption         =   "&About"
  178.    End
  179. Sub Command1_Click ()
  180.     'Add a new record to the master table
  181.     data1.Recordset.AddNew
  182.     'this has a TWO fold reason
  183.     ' 1) Set the user to enter data into the first field
  184.     '    (Text1 is avoided becuase it's a counter field)
  185.     ' 2) Peek at the TEXT2, LOSTFOCUS Event, this updates the database
  186.     '    Updating the database MUST be done prior to records being added
  187.     '    into secondary table(s)
  188.     Text2.SetFocus
  189. End Sub
  190. Sub Command2_Click ()
  191.     'Add a new record to the secondary table
  192.     data2.Recordset.AddNew
  193.     'this records the related field number into
  194.     'the Secondary table's relationship field
  195.     Text4.Text = Text1.Text
  196.     'make the text box that the user is going to enter
  197.     'data into the next available object
  198.     Text5.SetFocus
  199. End Sub
  200. Sub Data1_Reposition ()
  201.     'Set up a variable for the SQL to update secondary table's movement
  202.     ' i.e., when data1 moves to record 2,  data2 moves to those related records
  203.     Dim str1SQL As String
  204.     'this checks the SECONDARY table for it's related ID number
  205.     str1SQL = "Select * FROM Secondary WHERE MasterID = " & ""
  206.     'this makes sure the data conbtrols don't move past the last, or first record
  207.     'and give you a "No Current Record" error  (boo hiss)
  208.         If data1.Recordset.EOF Then
  209.         Beep
  210.         data1.Recordset.MoveLast
  211.         End If
  212.         If data1.Recordset.BOF Then
  213.         Beep
  214.         data1.Recordset.MoveFirst
  215.         End If
  216.       'this compares the Master table for it's related ID number
  217.       str1SQL = str1SQL & data1.Recordset.Fields("MasterID").Value & ""
  218.     'this does the actual movement of data2 (Secondary table) in relation to the Master table
  219.     data2.RecordSource = str1SQL
  220.     data2.Refresh
  221. End Sub
  222. Sub Form_Load ()
  223.     '---------------------------------------------
  224.     '|   This demo / example was written by      |
  225.     '|   James Wj Snyder,  Shattered Rose Studio |
  226.     '|   San Francisco, CA                       |
  227.     '|   NO warantees etc  (Come on, it's free)  |
  228.     '|                                           |
  229.     '|   Further info?  Ideas?  Complaints?      |
  230.     '|   Compu$erve  75141, 3544                 |
  231.     '|   Prodigy     NAPJ88A                     |
  232.     '|   Internet    SHATROSE@Hooked.Net         |
  233.     '|                                           |
  234.     '---------------------------------------------
  235. End Sub
  236. Sub Form_Unload (Cancel As Integer)
  237.     'the absolute exit, quit, etc etc
  238.     End
  239. End Sub
  240. Sub mnuAbout_Click ()
  241.     MsgBox "A quick n' dirty demo of relationships n' adding multiple to secondary table", 0, "James Wj Snyder Shattered Rose Studio"
  242. End Sub
  243. Sub mnuExit_Click ()
  244.     Unload AddNewRelationship
  245. End Sub
  246. Sub Text1_LostFocus ()
  247.     'this updates the MASTER table so that the secondary
  248.     'table can have records added to it
  249.     'this is ONLY one wat to update the table, there are tons more
  250.     ' (hey, it works for me...)
  251.     data1.Recordset.MovePrevious
  252.     data1.Recordset.MoveNext
  253. End Sub
  254. Sub Text2_LostFocus ()
  255.     'this updates the MASTER table so that the secondary
  256.     'table can have records added to it
  257.     'this is ONLY one wat to update the table, there are tons more
  258.     ' (hey, it works for me...)
  259.     data1.Recordset.MovePrevious
  260.     data1.Recordset.MoveLast
  261.     'Make the "AddNew - Secondary Table" the next object the user uses
  262.     ' (this is an option, but it makes peoples life easier)
  263.     Command2.SetFocus
  264. End Sub
  265.